package com.ygq.controller;

import DTO.AddChooseDTO;
import DTO.PageChooseQuestionDTO;
import DTO.UpdateChooseQuestionDTO;
import VO.ChooseQuestionVO;
import com.ygq.ChooseQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.PageResult;
import result.Result;

import java.util.List;

@RestController
@RequestMapping("/teacher/Choose")
public class ChooseQuestionController {

    @Autowired
    private ChooseQuestionService chooseQuestionService;

    /**
     * 分页查询
     * @param pageChooseQuestionDTO
     * @return
     */
    @PostMapping("/getChooseQuestion")
    public Result<PageResult> getChooseQuestion(@RequestBody PageChooseQuestionDTO pageChooseQuestionDTO){
        PageResult pageResult = chooseQuestionService.page(pageChooseQuestionDTO);
        return Result.success(pageResult);
    }

    /**
     * 添加题目   （选择题）
     * @param addChooseDTO
     * @return
     */
    @PostMapping("/addQuestion")
    public Result<String> addQuestion(@RequestBody AddChooseDTO addChooseDTO){
        if(addChooseDTO.getQuestionNumber() == null ||
            addChooseDTO.getChapterId() == null ||
            addChooseDTO.getAnswer() == null ||
            addChooseDTO.getDescription() == null||
            addChooseDTO.getOptionA() == null ||
            addChooseDTO.getOptionB() == null ||
            addChooseDTO.getOptionC() == null ||
            addChooseDTO.getOptionD() == null
        ){
            return Result.error("信息不全",301);
        }
        chooseQuestionService.addChoose(addChooseDTO);
        return Result.success("添加成功");
    }

    /**
     * 修改选择题
     * @param updateChooseQuestionDTO
     * @return
     */
    @PostMapping("/updateQuestion")
    public Result<String> updateQuestion(@RequestBody UpdateChooseQuestionDTO updateChooseQuestionDTO){
        if (chooseQuestionService.updateChoose(updateChooseQuestionDTO)==1){
            return Result.error("该试题关联了试卷，不能删除",512);
        };
        return Result.success("修改成功");
    }

    /**
     * 删除选择题
     * @param id
     * @return
     */
    @DeleteMapping("/deleteChoose")
    public Result<String> deleteChoose(Integer id){
        if (chooseQuestionService.deleteById(id)==1){
            return Result.error("该试题关联了试卷，不能删除",512);
        };
        return Result.success("删除成功");
    }

}
